package com.xpc.config;

import com.xpc.filter.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qinkuer
 * @version 1.0.0
 * @ProjectName UniversityGradeAdministrationSystem
 * @ClassName InterceptorConfig.java
 * @Description 配置文件. 配置拦截器.目前只用于配置TokenInterceptor
 * @createTime 2022年05月23日 13:01:00
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 放行路径
        List<String> patterns = new ArrayList();
//        patterns.add("/webjars/**");
//        patterns.add("/druid/**");
//        patterns.add("/sys/login");
//        patterns.add("/swagger/**");
//        patterns.add("/v2/api-docs");
//        patterns.add("/swagger-ui.html");
//        patterns.add("/swagger-resources/**");
        patterns.add("/login");
        registry.addInterceptor(tokenInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(patterns);
    }
}
